package xuegao.study.mall.rbac.service.impl;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xuegao.study.mall.common.model.ums.UmsResource;
import xuegao.study.mall.rbac.service.UmsResourceService;
import xuegao.study.mall.repo.dao.ums.UmsResourceDao;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UmsResourceServiceImpl implements UmsResourceService {

    @Autowired
    private UmsResourceDao umsResourceDao;

    @Override
    public List<UmsResource> list(Integer pageNum, Integer pageSize, Map<String, Object> params) {
        PageHelper.startPage(pageNum, pageSize);
        return umsResourceDao.selectList(params);
    }

    @Override
    public List<UmsResource> listAll() {
        return umsResourceDao.selectList(new HashMap<>());
    }

    @Override
    @Transactional
    public int insert(UmsResource resource) {
        resource.setCreateTime(new Date());
        return umsResourceDao.insertResource(resource);
    }

    @Override
    @Transactional
    public int update(Long id, UmsResource resource) {
        resource.setId(id);
        return umsResourceDao.updateResource(resource);
    }

    @Override
    @Transactional
    public int delete(Long id) {
        return umsResourceDao.deleteById(id);
    }
}
